﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	TemplateConverter.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Templates
{
	/// <summary>
	/// Value converter (copy values from template or from user to template context)
	/// </summary>
	public abstract class TemplateConverter
	{
		/// <summary>
		/// Template context
		/// </summary>
		public TemplateCtx Ctx { get; set; }

		/// <summary>
		/// Value converter (copy values from template or from user to template context)
		/// </summary>
		protected TemplateConverter(TemplateCtx ctx)
		{
			Ctx = ctx;
		}

		/// <summary>
		/// Loads user values in template context
		/// </summary>
		public virtual void LoadUserValuesToCtx(IDictionary<string, object> values)
		{
			if (values == null)
				return;

			var ctxValues = Ctx.Values;

			foreach (var kvp in values)
				ctxValues[kvp.Key] = kvp.Value;
		}

		/// <summary>
		/// Loads template values in template context
		/// </summary>
		public abstract void LoadTemplateValuesToCtx();
	}
}